Skip to content

Conversation

@kanikaa88
Copy link

Summary

Fixes reversed blog navigation links where "Previous" pointed to newer posts and "Next" pointed to older posts (reported in #7844).

Problem

Blog posts in sidebarBlog.json are ordered from newest to oldest (chronologically descending). The getRouteMeta function uses depth-first traversal, which sets:

  • prevRoute = routes that come before in traversal (newer posts)
  • nextRoute = routes that come after in traversal (older posts)

This caused "Previous" to point to newer posts and "Next" to point to older posts, which is backwards from expected blog navigation UX.

Solution

Swap prevRoute and nextRoute specifically for blog posts (section === 'blog') before passing them to DocsPageFooter. This ensures:

  • "Previous" → older posts (back in time) ✅
  • "Next" → newer posts (forward in time) ✅

Changes

  • Modified Page.tsx to swap routes only for blog section (lines 99-100)
  • Other sections (learn, reference, etc.) remain unchanged
  • Minimal change - only affects blog navigation

Testing

Verified locally:

  • Tested on http://localhost:3000/blog/2025/04/23/react-labs-view-transitions-activity-and-more
  • "Previous" correctly points to older post (February 14, 2025)
  • "Next" correctly points to newer post (October 1, 2025)
  • Navigation works correctly when clicking links

Before fix:

  • Previous → October 1, 2025 (newer) ❌
  • Next → February 14, 2025 (older) ❌

After fix:

  • Previous → February 14, 2025 (older) ✅
  • Next → October 1, 2025 (newer) ✅
Screenshot 2026-01-17 at 8 07 29 PM

Fixes #7844

Improve the explanation in the 'Fetching data' section to clearly
distinguish when an Effect is needed (synchronization with external
system) versus when it's not needed (user events, data transformation).

Closes reactjs#8226
Swap prevRoute and nextRoute for blog posts to fix navigation
direction. Blog posts are ordered newest to oldest, so the
traversal order is reversed from chronological order.

- Previous link now correctly points to older posts
- Next link now correctly points to newer posts

This only affects blog posts, other sections remain unchanged.

Fixes reactjs#7844
@github-actions
Copy link

github-actions bot commented Jan 17, 2026

Size changes

Details

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Five Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 128.14 KB (🟡 +15 B) 238.69 KB
/500 128.15 KB (🟡 +15 B) 238.7 KB
/[[...markdownPath]] 130.58 KB (🟡 +15 B) 241.13 KB
/errors 128.39 KB (🟡 +15 B) 238.94 KB
/errors/[errorCode] 128.37 KB (🟡 +15 B) 238.92 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

Copy link

@dakshverma23 dakshverma23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — fixes blog footer nav and clarifies the effects doc. Please add a one-line comment in Page.tsx explaining why next/prev are swapped for blog posts.

Add one-line comment explaining why next/prev routes are swapped
for blog posts (they're ordered newest to oldest).
@kanikaa88
Copy link
Author

Done! Added the comment. Thanks for the review! 🙌

LGTM — fixes blog footer nav and clarifies the effects doc. Please add a one-line comment in Page.tsx explaining why next/prev are swapped for blog posts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Blog article navigation links are backwards

2 participants